#include <bits/stdc++.h>
using namespace std;
#define int long long 

int n;
struct Info {
	int a, b, id;
	bool operator < (const Info &i) const {
		if (a + b != i.a + i.b) return a + b < i.a + i.b;
		return id < i.id;
	}
} a[100005];
set<Info> s;
bool cmp(const Info &a, const Info &b) {
	if (a.b != b.b) return a.b < b.b;
	return a.id < b.id;
}
signed main() {
	freopen("boast.in", "r", stdin);
	freopen("boast.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i].a >> a[i].b;
		a[i].id = i;
	}
	sort(a + 1, a + n + 1, cmp);
	for (int i = 1; i <= n; ++i) {
		s.insert(a[i]);
	}
	int ans = 1ll << 60;
	for (int i = 1; i <= n - 2; ++i) {
		Info fx = *(s.begin()); s.erase(fx);
		Info fx1 = *(s.begin()), fx2 = *(++s.begin());
		ans = min(ans, fx.a + fx1.a + fx2.a + fx1.b + fx2.b);
	}
	cout << ans << "\n";
	return 0;
}
